package com.sumainfor.pc.epc.controller.master;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.epc.feign.Zfeign.ZpcMktFeign;
import com.sumainfor.pc.epc.service.RepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/master/repair")
public class RepairController implements Serializable{

    @Autowired
    private RepairService repairService;

    @Autowired
    private ZpcMktFeign zpcMktFeign;
    /**
     * 查询维修工单列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2018/11/3 21:22
     */
    @RequestMapping(value = "/getRepairList",method = RequestMethod.GET)
    public JsonResult getRepairList(@RequestParam Map<String,Object>params,Pager pager){
        return repairService.getRepairList(params,pager);
    }
    /**
     * 查询维修工单列表
     * @Author zhlu
     * @Description //TODO
     * @Date 2018/11/3 21:22
     */
    @RequestMapping(value = "/getRepairMeList",method = RequestMethod.GET)
    public JsonResult getRepairMeList(@RequestParam Map<String,Object>params,Pager pager){
        return repairService.getRepairMeList(params,pager);
    }
    /**
     * 查询工作台 重要状态提醒 进行中工单 大修 紧急 小修
     */
    @RequestMapping(value = "/getRepairCountByUrgency",method = RequestMethod.GET)
    public JsonResult getRepairCountByUrgency(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        return  result.success(repairService.getRepairCountByUrgency(params));
    }

    /**
     * 点击受理 修改维修工单的状态
     * @param params
     * @return
     */
    @RequestMapping(value = "/updateRepState",method = RequestMethod.POST)
    public JsonResult updateRepState(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(repairService.updateRepState(params)){
            result.putSuccess("操作成功");
        }else{
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }
    /**
     * 获取所属房源的下拉列表
     * @param
     * @return
     */
    @RequestMapping(value = "/getCommunityName",method = RequestMethod.GET)
    public JsonResult getCommunityName(){
        return   zpcMktFeign.getCommunityName();
    }
    /**
     * 根据维修编号去查询领用单列表
     */
    @RequestMapping(value = "/getReceiveByRepId",method = RequestMethod.GET)
    public JsonResult getReceiveByRepId(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        List<Map<String,Object>> list= repairService.getReceiveByRepId(params);
        if(list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙");
        }
        return   result;
    }
    /**
     * 查询待接维修工单数
     */
    @GetMapping("/getRepairDaiCountList")
    public JsonResult getRepairDaiCountList() {
        JsonResult result=new JsonResult();
        Integer count=repairService.getRepairDaiCountList();
        if(count!=null){
            result.put(count);
        }else{
            result.putFailed("服务器繁忙");
        }
        return  result;
    }
    /**
     * 维修跟踪 待受理
     * @param params
     * @param pager
     * @return
     */
    @GetMapping("/getRepairListd")
    public JsonResult getRepairListd(@RequestParam Map<String,Object> params, Pager pager){
        JsonResult result=new JsonResult();
        System.out.println("params:"+params);
        return repairService.getRepairListd(params,pager);
    }
    /**
     *查询同房源的其他维修工单列表
     */
    @GetMapping("/getRepairHouList")
    public JsonResult getRepairHouList(@RequestParam Map<String,Object> params){
        return repairService.getRepairHouList(params);
    }


     /* 维修跟踪    已受理

     */
    @GetMapping("/getRepairListy")
    public JsonResult getRepairListy(@RequestParam Map<String,Object> params, Pager pager){
        JsonResult result=new JsonResult();
        System.out.println("params:"+params);
        return repairService.getRepairListy(params,pager);
    }

     /* 维修跟踪    已维修

     */
    @GetMapping("/getRepairListw")
    public JsonResult getRepairListw(@RequestParam Map<String,Object> params, Pager pager){
        JsonResult result=new JsonResult();
        System.out.println("params:"+params);
        return repairService.getRepairListw(params,pager);
    }

    /**
     * 租客报修生成报修单
     * @param params
     * @return
     */
    @RequestMapping(value = "/CreateRepair",method = RequestMethod.POST)
    public boolean createRepair(@RequestParam Map<String,Object> params){
        Boolean result = false;
        if(repairService.createRepair(params)){
            result = true;
        }
        return result;
    }
    /**
     * 维修师傅 修改工单为已完成
     * @param params
     * @return
     */
    @PostMapping("/updateOrdState")
    public JsonResult updateOrdState(@RequestParam Map<String,Object> params){
        return repairService.updateOrdState(params);
    }

}
